//
//  ManageDatabase.m
//  GR8_Iphl
//
//  Created by Tim Linsen on 11/01/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ManageDatabase.h"

@implementation ManageDatabase
@synthesize managedObjectContext=__managedObjectContext;

@synthesize managedObjectModel=__managedObjectModel;

@synthesize persistentStoreCoordinator=__persistentStoreCoordinator;

- (void) fillDatabaseLogin
{
    NSArray *studentnrs = [NSArray arrayWithObjects:@"2930359",@"2830448", nil];
    NSArray *wachtwoord = [NSArray arrayWithObjects:@"303747",@"453382",nil];
    
    for (NSString *studentnr in studentnrs)
    {
        NSManagedObject *obj = [NSEntityDescription insertNewObjectForEntityForName:@"Classes/Login" inManagedObjectContext:self.managedObjectContext];
        
        [obj setValue:studentnr forKey:@"stu_id"];
        
        [obj setValue:wachtwoord forKey:@"stu_wachtwoord"];
        
        [self.managedObjectContext insertObject:obj];
        
        
    }
    
    [self saveContext];
}
- (void)saveContext
{
    NSError *error = nil;
    NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
    if (managedObjectContext != nil)
    {
        if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error])
        {
            
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        } 
    }
}


@end
